/*
 * Copyright (c) 2009 Robert Esser
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package net.e2ser.component;

import java.io.IOException;

import net.e2ser.util.XMLWriter;
import android.graphics.Canvas;
import android.graphics.drawable.ShapeDrawable;


/**
 *
 * <p>Title: Petri Net Editor/Simulator</p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2009</p>
 * <p>Company: </p>
 * @author Rob Esser
 * @version 1.0
 */
abstract public class OneD extends AbstractElement {
  
  public AbstractComponent from, to;
  protected ShapeDrawable shape;

  public OneD(AbstractComponent from, AbstractComponent to) {
    this.from = from;
    this.to = to;
  }

  /**
   * draw myself on the Canvas
   * @param canvas where to draw
   */
  abstract public void draw(Canvas canvas);

  /**
   * notify my observers that my child comp has changed
   * @param comp AbstractComponent
   */
  public void changed(AbstractComponent comp) {
   from.changed(comp);
  }

  abstract public void resize(double scale);

  public void toXML(XMLWriter writer) throws IOException {
    //we don't have a name yet but the xml is all prepped
    String name = null;
    String cid = writer.addElement(this);
    String toid = writer.getID(to);
    String fromid = writer.getID(from);
    writer.writeLine("<arc id=\"" + cid + "\" to=\"" + toid + "\" from=\"" + fromid + 
        (name == null ? "" : "\" n = \"" + name) + "\"/>");
  }
  
}
